package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Kehuduan;
import com.ruoyi.system.service.IKehuduanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户端Controller
 * 
 * @author ruoyi
 * @date 2024-08-10
 */
@RestController
@RequestMapping("/system/kehuduan")
public class KehuduanController extends BaseController
{
    @Autowired
    private IKehuduanService kehuduanService;

    /**
     * 查询客户端列表
     */
    @PreAuthorize("@ss.hasPermi('system:kehuduan:list')")
    @GetMapping("/list")
    public TableDataInfo list(Kehuduan kehuduan)
    {
        startPage();
        List<Kehuduan> list = kehuduanService.selectKehuduanList(kehuduan);
        return getDataTable(list);
    }

    /**
     * 导出客户端列表
     */
    @PreAuthorize("@ss.hasPermi('system:kehuduan:export')")
    @Log(title = "客户端", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Kehuduan kehuduan)
    {
        List<Kehuduan> list = kehuduanService.selectKehuduanList(kehuduan);
        ExcelUtil<Kehuduan> util = new ExcelUtil<Kehuduan>(Kehuduan.class);
        util.exportExcel(response, list, "客户端数据");
    }

    /**
     * 获取客户端详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:kehuduan:query')")
    @GetMapping(value = "/{khdId}")
    public AjaxResult getInfo(@PathVariable("khdId") Long khdId)
    {
        return success(kehuduanService.selectKehuduanByKhdId(khdId));
    }

    /**
     * 新增客户端
     */
    @PreAuthorize("@ss.hasPermi('system:kehuduan:add')")
    @Log(title = "客户端", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Kehuduan kehuduan)
    {
        return toAjax(kehuduanService.insertKehuduan(kehuduan));
    }

    /**
     * 修改客户端
     */
    @PreAuthorize("@ss.hasPermi('system:kehuduan:edit')")
    @Log(title = "客户端", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Kehuduan kehuduan)
    {
        return toAjax(kehuduanService.updateKehuduan(kehuduan));
    }

    /**
     * 删除客户端
     */
    @PreAuthorize("@ss.hasPermi('system:kehuduan:remove')")
    @Log(title = "客户端", businessType = BusinessType.DELETE)
	@DeleteMapping("/{khdIds}")
    public AjaxResult remove(@PathVariable Long[] khdIds)
    {
        return toAjax(kehuduanService.deleteKehuduanByKhdIds(khdIds));
    }
}
